package com.xxwy.study.client.dispatcher;

import com.xxwy.study.common.OperationResult;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * .
 *
 * @author xxwy
 * @date 2021/11/23 0023
 */
public class RequestPendingCenter {

    private Map<Long, OperationResultFuture> map = new ConcurrentHashMap<>();

    public void add (Long streamId, OperationResultFuture future){
        map.put(streamId, future);
    }

    public void set (Long streamId, OperationResult operationResult){
        OperationResultFuture resultFuture = get(streamId);
        if (resultFuture != null) {
            resultFuture.setSuccess(operationResult);
            map.remove(streamId);
        }
    }

    public OperationResultFuture get(Long streamId) {
        return map.get(streamId);
    }
}
